/* 
 * Copyright (C) 2012 Martin Řehánek <Martin.Rehanek at mzk.cz>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

goog.provide('kramerius.audio.ui.MuteButton');

goog.require('kramerius.audio.ui.Button');
goog.require('kramerius.audio.debug_utils');
goog.require('goog.ui.Component');
goog.require('goog.ui.Control');

/** @const */ 
//var VOLUME_ENABLED = 'btnVolumeEnabled';
/** @const */ 
//var VOLUME_DISABLED = 'btnVolumeDisabled';

/** @const */ 
var MUTE_ON = 'btnMuteOn';
/** @const */ 
var MUTE_OFF = 'btnMuteOff';

/** @const */ 
var MUTE_BUTTON_STATE_MUTED = 'MUTE_MUTED';
/** @const */ 
var MUTE_BUTTON_STATE_UNMUTED = 'MUTE_UNMUTED';

/**
 * @constructor 
 * @param {Element} container Element containing this button.
 * @param {kramerius.audio.Controller} controller Controller of the audio player.
 */
kramerius.audio.ui.MuteButton =  function(container, controller){
    kramerius.audio.ui.Button.call(this, container, controller);
    this.controller_.setVolumeButton(this);
    /** @private */
    this.btnControl_ = this.initializeControl_();
    this.setStateUnmuted();
};
goog.inherits(kramerius.audio.ui.MuteButton, kramerius.audio.ui.Button);


/** @private */
kramerius.audio.ui.MuteButton.prototype.initializeControl_ = function(){
    var btnControl = new goog.ui.Control();
    //btnControl.setDispatchTransitionEvents(goog.ui.Component.State.ACTION, true);
    btnControl.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
    //console.log('INITIALIZING VOLUME CONTROL');
    var playerController = this.controller_;
    var button = this;
    goog.events.listen(btnControl, goog.ui.Component.EventType.ACTION,
        function (e) {
            //console.log('volumeButton ACTION');
            switch (button.getState()){
                case MUTE_BUTTON_STATE_UNMUTED:
                    //console.log("VolumeButton: muting");
                    playerController.mute();
                    break;
                case MUTE_BUTTON_STATE_MUTED:
                    //console.log("VolumeButton: unmuting");
                    playerController.unMute();
                    break;
            }
        });
    //kramerius.audio.debug_utils.appendDebugListeners(button, "volume button");
    btnControl.decorate(this.container_);
    //TODO: i18n
    return btnControl;
};

kramerius.audio.ui.MuteButton.prototype.setStateUnmuted= function(){
    this.setState_(MUTE_BUTTON_STATE_UNMUTED);
    this.setContainerClass_(MUTE_OFF);
    //this.setContainerClass_(VOLUME_ENABLED);
    new goog.ui.Tooltip(this.container_, "ztlumit");
};

//TODO: prejmenovat na setStateMuted
kramerius.audio.ui.MuteButton.prototype.setStateMuted = function(){
    this.setState_(MUTE_BUTTON_STATE_MUTED);
    this.setContainerClass_(MUTE_ON);
    //this.setContainerClass_(VOLUME_DISABLED);
    new goog.ui.Tooltip(this.container_, "obnovit hlasitost");
};

/** @private */
kramerius.audio.ui.MuteButton.prototype.setState_ = function(state){
    this.log_("setting state to " + state);
    this.state_ = state;
};

kramerius.audio.ui.MuteButton.prototype.getState = function(){
    return this.state_;
};


/** @private */
kramerius.audio.ui.MuteButton.prototype.log_= function(text){
    if(this.loggingEnabled_){
        console.log("MUTE button: " + text);
    }
};

